package example.remoteapp;

import java.util.ArrayList;

import jsso.annotation.Service;

import org.red5.logging.Red5LoggerFactory;
import org.red5.server.api.IScope;
import org.red5.server.api.so.ISharedObject;
import org.slf4j.Logger;


public class Application extends jsso.Application
{
	private static Logger log = Red5LoggerFactory.getLogger(Application.class, "oflaDemo");
	private IScope appScope;
	
	private ISharedObject sharedData;

	public boolean appStart (IScope app )
    {
        log.info( "Red5First.appStart" );
		appScope = app;
        
		sharedData = getSharedObject(this.appScope, "globalObject", true);

        return true;
    }

    @Service
    public Object hello() {
    	return "Hello World";
    }
    
    @Service
    public void setData(Object data) {
    	sharedData.setAttribute("data", data);
    }
    
    @Service
    public Object getData() {
    	return sharedData.getAttribute("data");
    }

    @Service
    public void setArray(ArrayList<String> data) {
    	sharedData.setAttribute("array", data);
    }
    
    @Service
    public Object getArray() {
    	return sharedData.getAttribute("array");
    }

    @Service
    public Object throwException() throws Exception {
    	throw new TestException("some error occured");
    }

    @Service
    public int add(int a, int b) {
    	return a+b;
    }

    @Service
    public Object echo(Object param) {
    	return param;
    }
    
    @Service
    public ArrayList<String> testArray() {
    	ArrayList<String> list = new ArrayList<String>();
    	list.add("test1");
    	list.add("test2");
    	return list;
    }
}